package request

import (
	"fox/common"
	"fox/models"
	"reflect"
)

type Role struct {
	Paging
	Name string `json:"name"`
}

type SaveRole struct {
	Name string `json:"name" binding:"required, min=6, max=10"`
}

type UpdateRole struct {
	ID       int64  `json:"id" binding:"required"`
	Name string `json:"nickname" binding:"omitempty,min=6,max=10"`
	Status int `json:"status" binding:"omitempty,min=-1,max=1"`
}

// ValidateRoleSortFile 检验字段是否在结构体中
func ValidateRoleSortFile(filed string) bool {
	var (
		role *models.Role
		ele reflect.Type
	)

	role = &models.Role{}
	ele = reflect.TypeOf(role).Elem()
	for i := 0; i < ele.NumField(); i++ {
		var tagSetting = common.ParseTagSetting(ele.Field(i).Tag.Get("gorm"), ";")
		if tagSetting["COLUMN"] == filed {
			return true
		}
	}
	return false
}
